<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        // 1. 数组的新增特性 - 扩展运算符
        let arr = [23, 13, 20, 30, 10, 33, [1, 2]];

        // let [n1, n2, n3, n4, n5, n6] = arr;
        // console.log(...arr);

        // 2. 扩展运算符的使用
        // console.log(Math.max(23, 13, 20, 30, 10, 33));
        // console.log(Math.max.apply(null, arr));
        // console.log(Math.max(...arr));

        // 2.1 拷贝数组 - 浅拷贝
        let arr1 = [...arr];
        // arr1.pop();
        // arr1[arr1.length - 1].pop();

        // console.log(arr);
        // console.log(arr1);

        // 3.0 操作对象
        var obj = {
            a: 10,
            b: 20,
            c: {
                d: 888
            }
        };

        // console.log(...obj); // 错误用法
        // 3.1 浅拷贝一个对象
        var obj1 = { ...obj };
        obj1.a = 100;
        obj1.c.d = 999;

        // console.log(obj);
        // console.log(obj1);


        // 4. 应用
        var a = [1, 2];
        var b = [2, 3];
        // console.log(a.concat(b));
        // console.log([...a, ...b]);

        // 剩余参数的其他用法 - 像扩展
        var list = ['apple', 'banana', 'orange', 'pear'];
        var [fruit, ...fArr] = list;
        console.log(fruit, fArr);

    </script>
</body>

</html>